<script>
	export default {
		name: "my-address"
	}
</script>
<script setup>
	import {
		computed,
		ref
	} from "vue";
	import {
		useUserStore
	} from '@/stores/user.js'
	const userStore = useUserStore()
	// 处理选择地址业务
	const chooseAddress = async () => {
		const res = await uni.chooseAddress()
		if (res.errMsg === 'chooseAddress:ok') {
			userStore.updateAddress(res)
		}
	}
</script>

<template>
	<view>
		<!-- 选择收货地址盒子 -->
		<view class="choose-address-box" v-if="JSON.stringify(userStore.address)==='{}'">
			<button type="primary" size="mini" class="choose-address-btn" @click="chooseAddress">请选择你的收货地址+</button>
		</view>
		<!-- 显示收货地址盒子 -->
		<view class="address-info-box" v-else @click="chooseAddress">
			<view class="row1">
				<view class="row1-left">
					<text class="username">收货人：{{userStore.address.userName}}</text>
				</view>
				<view class="row1-right">
					<text class="telephone">电话：{{userStore.address.telNumber}}</text>
					<uni-icons type="right" size="15"></uni-icons>
				</view>
			</view>
			<view class="row2">
				<view class="detailAddressTitle">
					收货地址：
				</view>
				<view class="detailAddress">{{userStore.addressStr}}</view>
			</view>
		</view>
	</view>
	<image src="/static/cart_border@2x.png" class="address-border-bottom"></image>
</template>


<style lang="scss">
	.address-border-bottom {
		display: block;
		width: 100%;
		height: 5px;
	}

	.choose-address-box {
		height: 90px;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #fff;

		.choose-address-btn {}
	}

	.address-info-box {
		background-color: #fff;
		padding: 0 10px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		min-height: 80px;
		font-size: 13px;

		.row1 {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.row2 {
			display: flex;
			align-items: center;
			margin-top: 10px;

			.detailAddressTitle {
				white-space: nowrap;
			}
		}
	}
</style>